package com.uenpay.im.invokeitems;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class BaseHttpInvokeItem extends HttpInvokeItem {

	public HttpInvokeResult getOutput() {
		return (HttpInvokeResult) GetResultObject();
	}

	protected void RequestHttpInvokeItem(boolean isPost) {
		if (isPost) {
			SetMethod("POST");
		}
		String url = APIConfiguration.getApiRootUrl();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		HttpInvokeResult result = new HttpInvokeResult();

		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return result;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		return result;
	}
}
